package rmy;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.rmy.common.core.text.Convert;
import rmy.domain.VoicCmd;
import rmy.domain.VoicParam;
import rmy.service.impl.OnbonBx06VoicDevice;
import rmy.service.impl.OnbonVoicDevice;

import java.util.ArrayList;
import java.util.List;

public class VoicUtils {


    /**
     * 通过参数获取驱动类型 1 仰邦
     * @param strParams
     * @return
     */
    public String getDriverType(String strParams) {
        JSONObject jsonObject = JSONObject.parse(strParams);
        return Convert.toStr(jsonObject.get("driver_type"));
    }

    /**
     * 解析成对象
     * @param strContent
     * @return
     */
    public static VoicCmd parseContent(String strContent){
        VoicCmd voicCmd = JSONObject.parseObject(strContent, VoicCmd.class);
        return voicCmd;
    }

    /**
     * 解析成对象
     * @param strParams
     * @return
     */
    public static VoicParam parseParams(String strParams){
        VoicParam voicParam = JSONObject.parseObject(strParams, VoicParam.class);
        return voicParam;
    }

    public static boolean sendVoic(String strIp, int nPort, String strParams, VoicCmd voicCmd) throws Exception {
        VoicParam voicParam = parseParams(strParams);
        // 1 仰邦
        switch (Convert.toStr(voicParam.driver_type, "1"))
        {
            case "2":
                new OnbonVoicDevice().sendVoic(strIp, nPort, voicParam, voicCmd);
                break;
            default:
                new OnbonBx06VoicDevice().sendVoic(strIp, nPort, voicParam, voicCmd);
                break;
        }
        return true;
    }

}
